home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / prog / tge129c.arj / SOURCE.ARJ / MOUSEPTR.C < prev    next >
C/C++ Source or Header  |  1993-08-20  |  5KB  |  185 lines

  1. /*****************************************************************************
  2. *       The Graphics Engine version 1.29ßC                                   *
  3. *                                                                            *
  4. *       The Graphics Engine code and documentation are Copyright (c) 1993    *
  5. *       by Matthew Hildebrand.                                               *
  6. *                                                                            *
  7. *       Unauthorised usage or modification of any or all of The Graphics     *
  8. *       Engine is strictly prohibited.                                       *
  9. *****************************************************************************/
  10.  
  11. #include <alloc.h>
  12. #include <stdlib.h>
  13. #include "tge.h"
  14. #include "tgemouse.h"
  15.  
  16.  
  17. /* More colours may, of course, be added. */
  18.  
  19. #define INVISIBLE    0
  20. #define    BLACK        1
  21. #define    WHITE        2
  22.  
  23.  
  24. /****
  25. ***** Pointer definitions.  0=invisible, 1=black, 2=white
  26. ****/
  27.  
  28. unsigned char arrowPointer[] = {        /* ARROW_POINTER */
  29.   6,0,8,0,            /* dimensions */
  30.   1,1,0,0,0,0,            /* pointer data */
  31.   1,2,1,0,0,0,
  32.   1,2,2,1,0,0,
  33.   1,2,2,2,1,0,
  34.   1,2,2,2,2,1,
  35.   1,2,1,2,1,1,
  36.   1,1,1,1,2,1,
  37.   0,0,0,1,1,1
  38. };
  39.  
  40. unsigned char targetPointer[] = {        /* TARGET_POINTER */
  41.   9,0,9,0,            /* dimensions */
  42.   0,0,0,1,1,1,0,0,0,
  43.   0,0,1,2,2,2,1,0,0,        /* pointer data */
  44.   0,1,2,1,1,1,2,1,0,
  45.   1,2,1,0,0,0,1,2,1,
  46.   1,2,1,0,2,0,1,2,1,
  47.   1,2,1,0,0,0,1,2,1,
  48.   0,1,2,1,1,1,2,1,0,
  49.   0,0,1,2,2,2,1,0,0,
  50.   0,0,0,1,1,1,0,0,0
  51. };
  52.  
  53. unsigned char bigArrowPointer[] = {        /* BIG_ARROW_POINTER */
  54.   11,0,18,0,            /* dimensions */
  55.   1,1,1,0,0,0,0,0,0,0,0,    /* pointer data */
  56.   1,2,1,1,0,0,0,0,0,0,0,
  57.   1,2,2,1,1,0,0,0,0,0,0,
  58.   1,2,2,2,1,1,0,0,0,0,0,
  59.   1,2,2,2,2,1,1,0,0,0,0,
  60.   1,2,2,2,2,2,1,1,0,0,0,
  61.   1,2,2,2,2,2,2,1,1,0,0,
  62.   1,2,2,2,2,2,2,2,1,1,0,
  63.   1,2,2,2,2,2,2,2,2,1,1,
  64.   1,2,2,2,2,2,2,2,2,2,1,
  65.   1,2,2,2,2,2,2,2,1,1,1,
  66.   1,2,2,2,2,2,2,1,1,0,0,
  67.   1,2,2,1,2,2,2,1,1,0,0,
  68.   1,2,1,1,1,2,2,2,1,0,0,
  69.   1,1,1,0,1,2,2,2,1,1,0,
  70.   0,0,0,0,1,1,2,2,2,1,0,
  71.   0,0,0,0,0,1,2,2,2,1,0,
  72.   0,0,0,0,0,1,1,1,1,1,0
  73. };
  74.  
  75. unsigned char bigTargetPointer[] = {        /* BIG_TARGET_POINTER */
  76.   15,0,15,0,            /* dimensions */
  77.   0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,
  78.   0,0,0,1,1,1,2,2,2,1,1,1,0,0,0,
  79.   0,0,1,1,2,2,2,2,2,2,2,1,1,0,0,
  80.   0,1,1,2,2,1,1,1,1,1,2,2,1,1,0,
  81.   0,1,2,2,1,1,0,0,0,1,1,2,2,1,0,
  82.   1,1,2,1,1,0,0,1,0,0,1,1,2,1,1,
  83.   1,2,2,1,0,0,1,2,1,0,0,1,2,2,1,
  84.   1,2,2,1,0,1,2,2,2,1,0,1,2,2,1,
  85.   1,2,2,1,0,0,1,2,1,0,0,1,2,2,1,
  86.   1,1,2,1,1,0,0,1,0,0,1,1,2,1,1,
  87.   0,1,2,2,1,1,0,0,0,1,1,2,2,1,0,
  88.   0,1,1,2,2,1,1,1,1,1,2,2,1,1,0,
  89.   0,0,1,1,2,2,2,2,2,2,2,1,1,0,0,
  90.   0,0,0,1,1,1,2,2,2,1,1,1,0,0,0,
  91.   0,0,0,0,0,1,1,1,1,1,0,0,0,0,0
  92. };
  93.  
  94. static unsigned char mousePointer[512];  /* default buffer size: 512b */
  95. static int curPointerNum = -1;          /* the current pointer */
  96.  
  97.  
  98. /****
  99. ***** Code
  100. ****/
  101.  
  102. void TGE_setupMousePointer(int pointerNum)
  103. {
  104.   unsigned char *src, *dest=mousePointer;
  105.   register unsigned count, max;
  106.   unsigned black, white;
  107.   unsigned wide, deep;
  108.   int xHotSpot, yHotSpot;
  109.  
  110.   curPointerNum = pointerNum;    /* update current pointer number */
  111.   switch (pointerNum)        /* set up proper source for pointer */
  112.   {
  113.     case ARROW_POINTER:        /* is it the arrow pointer? */
  114.       src = arrowPointer;
  115.       xHotSpot = 0;
  116.       yHotSpot = 0;
  117.       break;
  118.     case TARGET_POINTER:    /* is it the target pointer? */
  119.       src = targetPointer;
  120.       xHotSpot = 4;
  121.       yHotSpot = 4;
  122.       break;
  123.     case BIG_ARROW_POINTER:    /* is it the big arrow pointer? */
  124.       src = bigArrowPointer;
  125.       xHotSpot = 0;
  126.       yHotSpot = 0;
  127.       break;
  128.     case BIG_TARGET_POINTER:    /* is it the big target pointer? */
  129.       src = bigTargetPointer;
  130.       xHotSpot = 7;
  131.       yHotSpot = 7;
  132.       break;
  133.     default:            /* undefined */
  134.       return;
  135.   }
  136.  
  137.  
  138.   /* Find the colours closest to the ones in the pointer */
  139.  
  140.   black = colourCloseToX(0, 0, 0, 0);
  141.   white = colourCloseToX(255, 255, 255, 0);
  142.  
  143.  
  144.   wide = ((unsigned*)src)[0];        /* pointer dimensions */
  145.   deep = ((unsigned*)src)[1];
  146.   src += 4;
  147.   ((unsigned*)dest)[0] = wide;
  148.   ((unsigned*)dest)[1] = deep;
  149.   dest += 4;
  150.  
  151.  
  152.   /* Create the pointer bitmap using newly-found colour numbers */
  153.  
  154.   max = wide * deep;
  155.   for (count=0; count<max; count++)
  156.   {
  157.     switch (*src)            /* decide what to put in dest */
  158.     {
  159.       case BLACK:
  160.         *dest = black;
  161.         break;
  162.       case WHITE:
  163.         *dest = white;
  164.         break;
  165.       default:
  166.         *dest = *src;
  167.     }
  168.     src++;
  169.     dest++;
  170.   }
  171.  
  172.   /* Pass the bitmap to the driver */
  173.  
  174.   setPointerMouse(xHotSpot, yHotSpot, mousePointer);
  175. }
  176.  
  177.  
  178. /* Set up the same pointer again, thus possibly rechoosing the colours
  179.    composing the pointer.  This function is useful after the palette has
  180.    been changed, but you want the pointer to remain the same. */
  181.  
  182. void TGE_setPointerColours(void)
  183. {
  184.   setupMousePointer(curPointerNum);
  185. }